package com.fr.report.script.function;

import com.fr.base.core.DateUtils;
import com.fr.report.script.Function;
import com.fr.report.script.Function.Type;
import com.fr.report.script.NormalFunction;
import com.fr.report.script.Primitive;
import java.util.Date;
import java.util.GregorianCalendar;

public class WEEKDAY extends NormalFunction
{
  public Object run(Object[] paramArrayOfObject)
  {
    if (paramArrayOfObject.length < 1)
      return Primitive.ERROR_NAME;
    Date localDate = DateUtils.object2Date(paramArrayOfObject[0], false);
    GregorianCalendar localGregorianCalendar = new GregorianCalendar();
    localGregorianCalendar.setTime(localDate);
    return new Integer(localGregorianCalendar.get(7) - 1);
  }

  public Function.Type getType()
  {
    return Function.DATETIME;
  }

  public String getCN()
  {
    return "WEEKDAY(Serial_number):获取日期并返回星期数。返回值为介于0到6之间的某一整数，分别代表星期中的某一天（从星期日到星期六）。\nSerial_number:输入的日期\n备注:\nFineReport将日期保存为系列数，一个系列数代表一个与之匹配的日期，以方便用户对日期进行数值式计算。\n在1900年日期系统中，FineReport电子表格将1900年1月1日保存为系列数2，将1900年1月2日保存为系列数3，\n将1900年1月3日保存为系列数4……依此类推。如在1900年日期系统，1998年1月1日存为系列数35796。\n举例:\nWEEKDAY(\"2005/9/10\")等于6（星期六）。\nWEEKDAY(\"2005/9/11\")等于0（星期日）。\nWEEKDAY(35796)等于4（星期四）。\n";
  }

  public String getEN()
  {
    return "WEEKDAY(Serial_number):Returns the day of the week corresponding to a date. The day is given as an integer, ranging from 0(Sunday) to 6 (Saturday), by default.\nSerial_number is a sequential number that represents the date of the day you are trying to find.\n\nRemarks:\nFineReport stores dates as sequential serial numbers so they can be used in calculations.\nFineReport stores January 1, 1900 as serial number 2，January 2, 1900 as 3，\nJanuary 3, 1900 as 4, and so on, so January 1, 1998 as serial number 35796.\n\nExample:\n   WEEKDAY(\"2005/9/10\") = 6 (Saturday)\n   WEEKDAY(\"2005/9/11\") = 0 (Sunday)\n   WEEKDAY(35796) = 4 (Thursday)\n";
  }
}